import request from "@/utils/request";
const BASE_URL = "/visitor";

const VisitorAPI = {
  getList(queryParams: IPageQuery) {
    return request<any, PageResult<IPageVO[]>>({
      url: `${BASE_URL}/list`,
      method: "get",
      params: queryParams,
    });
  },
  getFormData(id: number) {
    return request({
      url: `${BASE_URL}/detail/${id}`,
      method: "get",
    });
  },

  add(data: IForm) {
    return request({
      url: `${BASE_URL}/create`,
      method: "post",
      data: data,
    });
  },

  update(data: IForm) {
    return request({
      url: `${BASE_URL}/update/${data.id}`,
      method: "POST",
      data: data,
    });
  },

  deleteByIds(id: number) {
    return request({
      url: `${BASE_URL}/delete/${id}`,
      method: "get",
    });
  },

  sendInvite(data: IShareForm) {
    return request({
      url: `${BASE_URL}/sendInvite`,
      method: "post",
      data: data,
    });
  },

  getInviteList(queryParams: IPageQuery) {
    return request<any, PageResult<InvitePageVO[]>>({
      url: `${BASE_URL}/inviteList`,
      method: "post",
      params: queryParams,
      data: queryParams,
    });
  },

  getCurrentVisitorsList(queryParams: IPageQuery) {
    return request<any, PageResult<InvitePageVO[]>>({
      url: `${BASE_URL}/currentVisitors`,
      method: "post",
      params: queryParams,
      data: queryParams,
    });
  },

  bindTag(data: BindTagForm) {
    return request({
      url: `${BASE_URL}/bindTag`,
      method: "post",
      data: data,
    });
  },
  unbindTag(id: number) {
    return request({
      url: `${BASE_URL}/unbindTag/${id}`,
      method: "get",
    });
  },

  getInviteInfoByInviteCode(inviteCode: string) {
    return request<any, InvitePageVO>({
      url: `${BASE_URL}/getInvite/${inviteCode}`,
      method: "get",
    });
  },

  getVisitorLocationList(visitorId: number) {
    return request<any, PageResult<VisitorLocationVo[]>>({
      url: `${BASE_URL}/getVisitorLocations/${visitorId}`,
      method: "get",
    });
  },

  countVisitorByToday() {
    return request<any, any>({
      url: `${BASE_URL}/countVisitorByToday`,
      method: "get",
    });
  },

  countStaffVisitorByToday() {
    return request<any, any>({
      url: `${BASE_URL}/countStaffVisitorByToday`,
      method: "get",
    });
  },

  deleteInvite(id: number) {
    return request({
      url: `${BASE_URL}/deleteInvite/${id}`,
      method: "get",
    });
  },

  createNoInviteVisitor(data: NoInviteForm) {
    data.tagNo = data.tagNo.toUpperCase();
    return request({
      url: `${BASE_URL}/createTempVisitor`,
      method: "post",
      data: data,
    });
  },

  getVisitorOpUserName() {
    return request<any, any>({
      url: `${BASE_URL}/getVisitorOpUserName`,
      method: "get",
    });
  },
  getVisitorInviteListOpUserName() {
    return request<any, any>({
      url: `${BASE_URL}/getVisitorInviteListOpUserName`,
      method: "get",
    });
  },
};

export default VisitorAPI;
export interface IPageVO {
  id: number;
  name: string;
  email: string;
  phone: string;
  remark: string;
  status: number;
  createAt: Date;
  updatedAt: Date;
  opName: string;
}

export interface IPageQuery extends PageQuery {
  keywords?: string;
  status?: number;
  statuses?: string[];
  localIds?: number[];
  startTime?: string;
  endTime?: string;
  opUserId?: number;
  opName?: string;
}
export interface IForm {
  id?: number;
  name: string;
  companyName: string;
  email: string;
  phone: string;
  remark: string;
  status: number;
  tagNo?: string;
}

export interface NoInviteForm {
  name: string;
  companyName: string;
  phone: string;
  status: number;
  tagNo: string;
}

export interface IShareForm {
  visitorId?: number;
  deptId: number | string;
  purposeId: number | string;
  planInAt: string;
  planOutAt: string;
}

export interface BindTagForm {
  id: number;
  tagNo: string;
}

export interface InvitePageVO {
  id: number;
  visitorName: string;
  deptName: string;
  purposeName: string;
  tagNo: string;
  status: number;
  planInAt: string;
  planOutAt: string;
  actInAt: string;
  actOutAt: string;
  opName: string;
}

export interface VisitorLocationVo {
  name: string;
  isForbid: number;
  updatedAt: string;
  createdAt: string;
}
